const express = require('express');
const userRouter = require('./api/user')
const roomRouter = require('./api/room')
const cors = require('cors')
const expressJWT =  require('express-jwt')
const config = require('./config')

const app = express();

app.use(cors())
app.use(express.json())

//配置jwt中间键
//出了api开头的都要验证

app.use(expressJWT({ secret: config.jwtSecretKey }).unless({ path: [/^\/api/] }))

//使用用户路由
app.use('/api',userRouter);
//使用room路由
app.use('/api',roomRouter)
//启动服务器
app.listen('3000',()=>{
    console.log('服务器运行在 http://localhost:3000')
})